package com.moss.cloud.base.biz.controller;
import com.moss.cloud.base.api.model.from.BaseFrom;
import com.moss.cloud.base.api.model.from.FlowBusinessFrom;
import com.moss.cloud.base.api.model.from.TaskFrom;
import com.moss.cloud.base.api.model.param.FlowBusinessParam;
import com.moss.cloud.base.biz.service.IFlowBusinessService;
import com.moss.cloud.common.core.constant.ServiceList;
import com.moss.cloud.common.core.model.Result;
import com.moss.cloud.common.security.annotation.SysLog;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
* 业务流程前端控制器
*
* @author 瑾年
* @date 2024-03-06
*/
@RestController
@RequestMapping(ServiceList.BASE + "/flowBusiness")
public class FlowBusinessController {

    private final IFlowBusinessService flowBusinessService;

    public FlowBusinessController(IFlowBusinessService flowBusinessService) {
        this.flowBusinessService = flowBusinessService;
    }

    /**
    * 分页查询
    *
    * @param param
    * @return
    */
    @PostMapping("/page")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "分页查询")
    public Result<?> page(@RequestBody @Validated FlowBusinessParam param) {
        return Result.success(flowBusinessService.page(param));
    }

    /**
    * 新增
    *
    * @param from
    * @return
    */
    @PostMapping("/save")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "新增业务流程")
    public Result<?> save(@RequestBody @Validated FlowBusinessFrom from) {
        return Result.success(flowBusinessService.saveFlowBusiness(from));
    }

    /**
    * 更新
    *
    * @param from
    * @return
    */
    @PostMapping("/update")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "更新业务流程")
    public Result<?> update(@RequestBody @Validated FlowBusinessFrom from) {
        return Result.success(flowBusinessService.update(from));
    }

    /**
    * 删除
    *
    * @param baseFrom
    * @return
    */
    @PostMapping("/remove")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "删除业务流程")
    public Result<?> remove(@RequestBody @Validated BaseFrom baseFrom) {
        return Result.success(flowBusinessService.remove(baseFrom));
    }

    /**
    * 详情
    *
    * @param baseFrom
    * @return
    */
    @PostMapping("/detail")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "业务流程详情")
    public Result<?> detail(@RequestBody @Validated BaseFrom baseFrom) {
        return Result.success(flowBusinessService.detail(baseFrom));
    }

    /**
     * 获取任务节点
     *
     * @param from
     * @return
     */
    @PostMapping("/nodeTasks")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "获取任务节点")
    public Result<?> nodeTasks(@RequestBody @Validated TaskFrom from){
        return Result.success(flowBusinessService.nodeTasks(from));
    }

}
